package cn.piaoyi.service.imp;

import java.util.*;
import org.apache.commons.logging.*;
import cn.piaoyi.bean.Category;
import cn.piaoyi.dao.CategoryDAO;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.CategoryService;


public class CategoryServiceImp implements CategoryService {

	private static final Log logger = LogFactory.getLog(CategoryServiceImp.class);
	
	private CategoryDAO categoryDAO;

	public CategoryDAO getCategoryDAO() {
		return categoryDAO;
	}

	public void setCategoryDAO(CategoryDAO categoryDAO) {
		this.categoryDAO = categoryDAO;
	}

	/**
	 * 保存Category对象
	 * 
	 * @param admin
	 * 			Category对象
	 * @return Category
	 * 			Category对象
	 */
	public Category createCategory(Category category) throws PiaoyiException{
		try {
			category = this.getCategoryDAO().saveCategory(category);
			return category;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据code获取Category对象
	 * 
	 * @param code
	 * 			String
	 * @return Category
	 * 			Category对象
	 */
	public Category findCategoryByCode(String code){
		return this.getCategoryDAO().findCategoryByCode(code);
	}
	
	/**
	 * 更新Category对象
	 * 
	 * @param category
	 * 			Category对象
	 * @return Category
	 * 			Category对象
	 */
	public Category updateCategory(Category category) throws PiaoyiException{
		try {
			category = this.getCategoryDAO().updateCategory(category);
			return category;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据主键ID获取Category对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Category
	 * 			Category对象
	 */
	public Category findCategoryById(long id){
		return this.getCategoryDAO().findCategoryById(id);
	}
	
	/**
	 * 获取Category列表
	 * 
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @return List
	 * 			Admin对象列表
	 */
	public List findCategorys(String orderby, int ascOrDesc){
		return this.getCategoryDAO().findCategorys(orderby, ascOrDesc);
	}
	
	/**
	 * 删除Category对象
	 */
	public void removeCategoryById(long id){
		this.getCategoryDAO().removeCategoryById(id);
	}
}
